<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="p" uri="/WEB-INF/tld/privilege.tld"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>查看费用详情</title>
<base href="<%=basePath%>" />
<%@ include file="../../cuv_include.jsp"%>
<style type="text/css">
fieldset,legend,form,table,tr,td,textarea {
	margin: 0;
	padding: 0
}

table {
	margin: 10px 10px
}

;
td {
	line-height: 40px;
}

label {
	font-weight: bold;
}

input[type="text"] {
	width: 250px;
}

input[type="password"] {
	width: 250px;
}

input[type="textarea"] {
	width: 250px;
}

textarea {
	width: 250px;
	overflow-y: auto;
	resize: none;
}

.text {
	width: 250px;
}
</style>

<script type="text/javascript">
    $(document).ready(function() { 
    	var options = {dataType: 'json', beforeSubmit: beforeSubmit, success: process};
        $("#actionForm").submit(function(){
        	$("#btn_reply").attr("disabled", "disabled");
            $(this).ajaxSubmit(options);
            return false;
        });
    	
    	$("#btn_pass").click(function(){
    		$("#btn_pass").attr("disabled", "disabled");
    		var id = $("#id").val();
    		$.get("pjcost/cost/pass.do", {id:id}, function(data) {
    			$("#btn_pass").removeAttr("disabled");
    			var result = $.parseJSON(data);
    			if(result.code == 1) {
    				alert("审核成功!");
    			} else {
    				alert(result.message);
    			}
    		});
    		var qs = $("#qs").val();
    		location.href="<%=basePath%>pjcost/cost/list.do?"+ qs;;
       	});
    	$("#btn_pass_region").click(function(){
    		$("#btn_pass_region").attr("disabled", "disabled");
    		var id = $("#id").val();
    		$.get("pjcost/cost/regionpass.do", {id:id}, function(data) {
    			$("#btn_pass_region").removeAttr("disabled");
    			var result = $.parseJSON(data);
    			if(result.code == 1) {
    				alert("审核成功!");
    			} else {
    				alert(result.message);
    			}
    		});
    		var qs = $("#qs").val();
    		location.href="<%=basePath%>pjcost/cost/list.do?"+ qs;;
       	});
    	
    	$("#btn_refuse").click(function(){
    		$("#btn_refuse").attr("disabled", "disabled");
    		var id = $("#id").val();
    		$.get("pjcost/cost/refuse.do", {id:id}, function(data) {
    			$("#btn_refuse").removeAttr("disabled", "disabled");
    			var result = $.parseJSON(data);
    			if(result.code == 1) {
    				alert("记录拒绝成功!");
    			} else {
    				alert(result.message);
    			}
    		});
    		var qs = $("#qs").val();
    		location.href="<%=basePath%>pjcost/cost/list.do?"+ qs;;
    	});
    	
    	$("#btn_regionrefuse").click(function(){
    		$("#btn_regionrefuse").attr("disabled", "disabled");
    		var id = $("#id").val();
    		$.get("pjcost/cost/regionrefuse.do", {id:id}, function(data) {
    			$("#btn_regionrefuse").removeAttr("disabled");
    			var result = $.parseJSON(data);
    			if(result.code == 1) {
    				alert("记录拒绝成功!");
    			} else {
    				alert(result.message);
    			}
    		});
    		var qs = $("#qs").val();
    		location.href="<%=basePath%>pjcost/cost/list.do?" + qs;
		});
    	
    	$("#btn_closerecord").click(function(){
    		$("#btn_closerecord").attr("disabled", "disabled");
    		var id = $("#id").val();
    		$.get("pjcost/cost/closerecord.do", {id:id}, function(data){
    			$("#btn_closerecord").removeAttr("disabled");
    			var result = $.parseJSON(data);
    			if(result.code == 1) {
    				alert("记录归档成功!");
    			} else {
    				alert(result.message);
    			}
    		});
    		var qs = $("#qs").val();
    		location.href="<%=basePath%>pjcost/cost/list.do?" + qs;
    	});
	});

	function beforeSubmit() {
		if (isEmpty($("#content").val())) {
			alert("回复内容不能为空！");
			$("#btn_reply").removeAttr("disabled");
			return false;
		}
		return true;
	}

	function process(responseJson) {
		$("#btn_reply").removeAttr("disabled");
		if (responseJson.code == 0) {
			$('#error_label').text("错误信息：" + responseJson.message);
			$("#p_error").show();
			return;
		} else {
			var str = "<div style='word-wrap:break-word; word-break:normal; margin: 10px 0 0 0; line-height: 1.6;'>"+
     		responseJson.createtime+"&nbsp;&nbsp;<font color='red'>"+responseJson.username+"</font>："+
     		"<span style='color:#00A;'>"+responseJson.content+"</span></div>";
	        $("#commentSet").prepend(str);
	  		$("#content").val("");
		}
	}
</script>
</head>

<body>
	<div style="width: 1208px;">
	<input id="qs" name="qs" type="hidden" value="${qs}" />
		<div style="float: left;">
			<table>
				<tr>
					<td><label for="id">ID：</label></td>
					<td><input type="text" name="id" id="id" readonly="readonly"
						value="${cost.id }" class="text" /></td>
				</tr>
				<tr>
					<td><label for="applyUser">申请人：</label></td>
					<td><input type="text" class="text" name="applyUser"
						disabled="disabled" id="applyUser"
						value="${recordApplyUser.cnname}" /></td>
				</tr>
				<tr>
					<td><label for="applyTime">申请日期：</label></td>
					<td><input type="text" class="text" name="applyTime"
						id="applyTime" disabled="disabled" value="${cost.applyTime }" />
					</td>
				</tr>
				<tr>
					<td><label for="applyReason">申请理由</label></td>
					<td valign="top"><textarea name="applyReason" id="applyReason"
							cols="34" rows="8" readonly="readonly"><c:out value="${cost.applyReason }" /></textarea>
					</td>
				</tr>
				<tr>
					<td><label for="expectCost">预算金额：</label></td>
					<td><input type="text" name="expectCost" id="expectCost"
						value=<fmt:formatNumber type="number" value="${cost.expectCost }" />
						onkeyup="this.value=this.value.replace(/[^0-9\.]/gi,'')"
						disabled="disabled" />
				</tr>
				<tr>
					<td><label for="actualCost">实际总额：</label></td>
					<td><input type="text" name="actualCost" class="text"
						id="actualCost" disabled="disabled"
						value="<fmt:formatNumber type="number" value="${cost.actualCost }" />" />
					</td>
				</tr>
				<tr>
					<td valign="top"><label for="actualDesc">实际细项描述：</label></td>
					<td><textarea name="actualDesc" id="actualDesc" cols="34"
							rows="4" readonly="readonly"><c:out value="${cost.actualDesc }" /></textarea>
					</td>
				</tr>
				<tr>
					<td valign="top"><label for="wipeoutUser">报销人：</label></td>
					<td><input type="text" name="wipeoutUser" id="wipeoutUser"
						disabled="disabled" class="text" value="${cost.wipeoutUser } " />
					</td>
				</tr>
				<tr>
					<td valign="top"><label for="provinces">省份：</label></td>
					<td><select id="provinces" name="provinces"
						style="width: 253px;" disabled="disabled">
							<option value="" style="color: red;">选择省份</option>
							<c:forEach items="${provinces}" var="entry" varStatus="status">
								<option value="${entry.key }"
									<c:if test="${entry.key == cost.province }">selected ="true"</c:if>>
									${entry.value }</option>
							</c:forEach>
					</select></td>
				</tr>
				<tr>
					<td valign="top"><label for="remark">记录描述：</label></td>
					<td valign="top"><textarea name="remark" id="remark" cols="34"
							rows="5" readonly="readonly"><c:out value="${cost.remark } " /></textarea>
					</td>
				</tr>
				<tr>
					<td><label for="status">记录状态：</label></td>
					<td><c:if test="${cost.status == 0 }">
							<input class="text" type="text" name="status" disabled="disabled"
								value="已提交" />
						</c:if> <c:if test="${cost.status == 1 }">
							<input type="text" class="text" name="status" disabled="disabled"
								value="审核中" />
						</c:if> <c:if test="${cost.status == 2 }">
							<input type="text" name="status" class="text" disabled="disabled"
								value="已拒绝" />
						</c:if>
						<c:if test="${cost.status == 3 }">
							<input type="text" name="status" class="text" disabled="disabled"
								value="结项中" />
						</c:if>
						<c:if test="${cost.status == 4 }">
							<input type="text" name="status" class="text" disabled="disabled"
								value="归档中" />
						</c:if>
						<c:if test="${cost.status == 5 }">
							<input type="text" name="status" class="text" disabled="disabled"
								value="已归档" />
						</c:if></td>
				</tr>
				<tr>
					<td><label for="checkstatus">审核详情：</label></td>
					<td valign="top"><textarea name="checkStatus" id="checkStatus"
							cols="34" rows="5" readonly="readonly"><c:out value="${recordMap[cost.id] } " /></textarea>
					</td>
				</tr>
				<tr>
					<td><input type="button" id="btn_back" value="返回" class="text"
						onclick="history.go(-1);" style="width: 80px;" /></td>
					<td><p:chkPri actionUrl="pjcost/cost/pass.do">
							<c:if test="${marketcheckstatus == 0 and cost.status != 2}">
								<input id="btn_pass" type="button" value="通过" class="text"
									style="width: 80px;" />
							</c:if>
						</p:chkPri> <p:chkPri actionUrl="pjcost/cost/refuse.do">
							<c:if test="${marketcheckstatus == 0 and cost.status != 2}">
								<input id="btn_refuse" type="button" value="拒绝"
									style="width: 80px;" />
							</c:if>
						</p:chkPri> <p:chkPri actionUrl="pjcost/cost/regionpass.do">
							<c:if test="${regioncheckstatus == 0 and cost.status != 2}">
								<input id="btn_pass_region" type="button" value="通过"
									style="width: 80px;" />
							</c:if>
						</p:chkPri> <p:chkPri actionUrl="pjcost/cost/regionrefuse.do">
							<c:if test="${regioncheckstatus == 0 and cost.status != 2}">
								<input id="btn_regionrefuse" type="button" value="拒绝"
									style="width: 80px;" />
							</c:if>
						</p:chkPri> <p:chkPri actionUrl="pjcost/cost/closerecord.do">
							<input type="button" id="btn_closerecord" value="归档"
								style="width: 80px;"
								<c:if test="${cost.status == 5}">disabled="true"</c:if> />
						</p:chkPri></td>
				</tr>
			</table>
		</div>

		<div style="float: left">
			<div id="commentSet" style="width: 500px; margin: 20px 0 0 50px;">
				<c:forEach items="${comments }" var="comment" varStatus="status">
					<div
						style="word-wrap: break-word; word-break: normal; margin: 10px 0 0 0; line-height: 1.6;">
						<fmt:formatDate value="${comment.createTime}" type="both"
							dateStyle="medium" timeStyle="medium" />
						&nbsp;&nbsp;<font color="red">${comment.userCnname}</font>： <span
							style="color: #00A;">${comment.content}</span>
					</div>
				</c:forEach>
			</div>
			<form id="actionForm" method="post" action="pjcost/cost/reply.do">
				<table style="margin: 20px 0 0 50px;">
					<tr>
						<td valign="top"><label for="newreply">新回复：</label></td>
						<td valign="top"><textarea name="content" id="content"
								cols="40" rows="3"><c:out value="${newreply.content }"></c:out></textarea> 
							<input type="text" id="costId" class="text" name="costId"
							value="${cost.id}" style="display: none;" />
						</td>
					</tr>
					<tr>
						<td></td>
						<td><p:chkPri actionUrl="pjcost/cost/reply.do">
								<input type="submit" id="btn_reply" value="提交"
									style="width: 80px;" />
							</p:chkPri></td>
					</tr>
				</table>
			</form>
		</div>	
	</div>
</body>
</html>